<template>
    <el-form ref="form" :model="form" :rules="rules">
        <el-form-item prop="name" label="功能名">
            <el-input v-model="form.name" :maxlength="50"/>
        </el-form-item>
        <el-form-item prop="path" label="鉴权串">
            <el-input v-model="form.path" :maxlength="50"/>
        </el-form-item>
        <el-form-item prop="ext" label="接口路径">
            <el-input class="pre-line" type="textarea" :autosize="true" v-model="form.ext" :maxlength="500"/>
        </el-form-item>
        <el-form-item class="text-center">
            <el-button type="primary" @click="submit" :loading="btnload">提交</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
    import {ruleAct} from "@/api";

    export default {
        data() {
            return {
                rules: {
                    name: [
                        {required: true, message: '不能为空', trigger: 'blur'}
                    ]
                    , path: [
                        {required: true, message: '不能为空', trigger: 'blur'}
                    ]
                    , ext: [
                        {required: true, message: '不能为空', trigger: 'blur'}
                    ]
                }
                , btnload: false
                , form: {
                    name: '',
                    path: '',
                    ext: '',
                }
            }
        }
        , props: ['pdata']
        , mounted() {
            if (this.pdata.row != null) {
                this.form.id = this.pdata.row.id;
                this.form.name = this.pdata.row.name;
                this.form.path = this.pdata.row.path;
                this.form.ext = this.pdata.row.ext;
                this.form.parent = this.pdata.parent;
            } else {
                this.form.parent = this.pdata.parent.id;
            }
        }
        , methods: {
            submit() {
                this.$submit(this.$refs['form'], () => {
                    ruleAct(this.form, 'post', () => {
                        this.$emit('close', true);
                    }, () => {
                        this.btnload = false;
                    })
                })
            }
        }
    }
</script>
